// package hn.cch.security;
//
// import hn.cch.constant.KeyConstant;
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.security.authentication.AuthenticationProvider;
// import org.springframework.security.core.Authentication;
// import org.springframework.security.core.AuthenticationException;
// import org.springframework.security.core.userdetails.UserDetails;
// import org.springframework.security.core.userdetails.UserDetailsService;
// import org.springframework.stereotype.Component;
// import org.springframework.web.context.request.RequestContextHolder;
// import org.springframework.web.context.request.ServletRequestAttributes;
//
// import javax.servlet.http.HttpServletRequest;
//
// @Component
// public class AuthenticationProviderImpl implements AuthenticationProvider {
//
//     @Autowired
//     private UserDetailsService userDetailsService;
//
//     @Override
//     public Authentication authenticate(Authentication authentication) throws AuthenticationException {
//
//         MyAbstractAuthenticationToken authenticationToken = (MyAbstractAuthenticationToken) authentication;
//         String mobile = (String) authenticationToken.getPrincipal();
//
//         HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//         String code = request.getParameter(KeyConstant.SMS_CODE_PARAMETER_KEY);
//
//         // todo check sms code
//
//         UserDetails userDetails = userDetailsService.loadUserByUsername(mobile);
//         MyAbstractAuthenticationToken token = new MyAbstractAuthenticationToken(userDetails.getAuthorities(), userDetails);
//         token.setDetails(authenticationToken.getDetails());
//         return token;
//     }
//
//     @Override
//     public boolean supports(Class<?> clazz) {
//         return MyAbstractAuthenticationToken.class.isAssignableFrom(clazz);
//     }
// }
